package com.functionx.provider;

import com.functionx.contract.ISignatureDesign;
import com.functionx.utils.HttpUtil;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class SignatureDesignService implements ISignatureDesign {

    @Override
    public String generateSignatureDesignUrl(String name, int type) {
        String url = "http://www.yishuzi.com/b/re13.php";
        Map<String, Object> params = new HashMap<>();
        params.put("id", name);
        params.put("idi", "jiqie");
        params.put("id1", type);//6-39.签名字体 17-43.行书 901-36.一笔艺术签 905-37.一笔商务签
        params.put("id2", "#FFFFFF");
        params.put("id3", "");
        params.put("id4", "#FFFFFF");
        params.put("id5", "");
        params.put("id6", "#000000");
        String response = HttpUtil.doPost(url, params);
        String startStr = "<img src=\"";
        String endStr = "\">";
        int startIndex = response.indexOf(startStr) + startStr.length();
        int endIndex = response.indexOf(endStr);
        String signatureDesignUrl = response.substring(startIndex, endIndex);
        return signatureDesignUrl;
    }
}
